package com.appwoo.txtws.component;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import java.util.Observable;
import java.util.Observer;

public class ImageZoomView extends View
  implements Observer
{
  private float mAspectQuotient;
  private Bitmap mBitmap;
  private final Paint mPaint = new Paint(2);
  private final Rect mRectDst = new Rect();
  private final Rect mRectSrc = new Rect();
  private ZoomState mState;

  public ImageZoomView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
  }

  private void calculateAspectQuotient()
  {
    if (this.mBitmap != null)
      this.mAspectQuotient = (this.mBitmap.getWidth() / this.mBitmap.getHeight() / (getWidth() / getHeight()));
  }

  protected void onDraw(Canvas paramCanvas)
  {
    if ((this.mBitmap != null) && (this.mState != null))
    {
      int i = getWidth();
      int j = getHeight();
      int k = this.mBitmap.getWidth();
      int m = this.mBitmap.getHeight();
      float f1 = this.mState.getPanX();
      float f2 = this.mState.getPanY();
      float f3 = this.mState.getZoomX(this.mAspectQuotient) * i / k;
      float f4 = this.mState.getZoomY(this.mAspectQuotient) * j / m;
      this.mRectSrc.left = ((int)(f1 * k - i / (2.0F * f3)));
      this.mRectSrc.top = ((int)(f2 * m - j / (2.0F * f4)));
      this.mRectSrc.right = ((int)(this.mRectSrc.left + i / f3));
      this.mRectSrc.bottom = ((int)(this.mRectSrc.top + j / f4));
      this.mRectDst.left = getLeft();
      this.mRectDst.top = getTop();
      this.mRectDst.right = getRight();
      this.mRectDst.bottom = getBottom();
      if (this.mRectSrc.left < 0)
      {
        Rect localRect4 = this.mRectDst;
        localRect4.left = ((int)(localRect4.left - f3 * this.mRectSrc.left));
        if (this.mRectDst.left > i - 100)
          this.mRectDst.left = (i - 100);
        this.mRectSrc.left = 0;
      }
      if (this.mRectSrc.right > k)
      {
        Rect localRect3 = this.mRectDst;
        localRect3.right = ((int)(localRect3.right - f3 * (this.mRectSrc.right - k)));
        if (this.mRectDst.right < 100)
          this.mRectDst.right = 100;
        this.mRectSrc.right = k;
      }
      if (this.mRectSrc.top < 0)
      {
        Rect localRect2 = this.mRectDst;
        localRect2.top = ((int)(localRect2.top - f4 * this.mRectSrc.top));
        if (this.mRectDst.top > j - 100)
          this.mRectDst.top = (j - 100);
        this.mRectSrc.top = 0;
      }
      if (this.mRectSrc.bottom > m)
      {
        Rect localRect1 = this.mRectDst;
        localRect1.bottom = ((int)(localRect1.bottom - f4 * (this.mRectSrc.bottom - m)));
        if (this.mRectDst.bottom < 100)
          this.mRectDst.bottom = 100;
        this.mRectSrc.bottom = m;
      }
      if (this.mRectSrc.top > m)
        this.mRectSrc.top = m;
      if (this.mRectSrc.left > k)
        this.mRectSrc.top = k;
      paramCanvas.drawBitmap(this.mBitmap, this.mRectSrc, this.mRectDst, this.mPaint);
    }
  }

  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4);
    calculateAspectQuotient();
  }

  public void setImage(Bitmap paramBitmap)
  {
    this.mBitmap = paramBitmap;
    calculateAspectQuotient();
    invalidate();
  }

  public void setZoomState(ZoomState paramZoomState)
  {
    if (this.mState != null)
      this.mState.deleteObserver(this);
    this.mState = paramZoomState;
    this.mState.addObserver(this);
    invalidate();
  }

  public void update(Observable paramObservable, Object paramObject)
  {
    invalidate();
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.component.ImageZoomView
 * JD-Core Version:    0.6.2
 */